#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <fstream>
#include <string>
#include <stdio.h>
#include <cstring>

using namespace std;

int main()
{
    int fd = open("./test1.txt", O_RDONLY);
    
    // lseek：改变文件的偏移量
    // 也可以使用lseek获得文件的大小，比较方便
    off_t length = lseek(fd, -3, SEEK_END);
    cout << "length:" << length << endl;

    char buffer [2] = { 0 };
    read(fd, buffer, sizeof(buffer));
    cout << "buffer:" << buffer << endl;

    return 0;
}